import * as types from './actionTypes';
import Util from '../common/utils';

export let fetchBanner = () => {
	let url = global.U + '/api/us/gc/ad/list';

    return dispatch => {

        // 请求轮播数据
        dispatch(fetchBannerlist());

        return Util.post(url, {'type' : '0'}, (response) => {
            dispatch(receiveBannerlist(response.data));
        }, (error) => {
            console.log('Fetch Banner list error: ' + error);
            dispatch(receiveBannerlist([]));
        });
    }
};

export let fetchBannerlist = () => {
	return {
		'type' : types.FETCH_BANNER_LIST,
	}
};

export let receiveBannerlist = (bannerList) => {
	return {
		'type' : types.RECEIVE_BANNER_LIST,
		'bannerList' : bannerList
	}
};
